<?php
class ShanghaiWeather {
	
	function getTodayWether($html) {
		$d002s = $html->find(".d002s",0);
		
		$order = array (
				"\r\n",
				"\n",
				"\r"
		);
		$replace = '';
		$text = str_replace ( $order, $replace, $d002s->plaintext);
		$parsed = preg_split ( '/ +/', $text ); // one or more spaces
		$days = array ();
		foreach ( $parsed as $temp ) {
			// echo $temp;
			if (! empty ( $temp ) && strlen ( trim ( $temp ) ) > 0) {
				// echo $temp.'='.strlen(trim($temp));
				$days [] = trim ( $temp );
			}
		}
		return $days;
	}
	
	function getTodayLife($html) {
		$todayWeather001 = $html->find(".TodayWeather001s");
		$theData = array();
		foreach($todayWeather001[0]->find('tr') as $row) {
			$tdCount = 0;
			foreach($row->find('td') as $cell) {
				//echo $cell->plaintext . "<br/>";
				$temp = str_replace("&nbsp;","", $cell->plaintext);
				if(!empty($temp)&&strlen(trim($temp))>0){
					$result = str_replace(" ", "",trim($temp));
					$theData[] = $result;
				}
				$tdCount++;
			}
		}
		return $theData;
	}
	
	function getFiveWeather($html) {
		$order = array (
				"\r\n",
				"\n",
				"\r" 
		);
		$replace = '';
		$fivedays = $html->find("[class*='qiriWeather']");
		$div = $fivedays[0];
		
		$text = str_replace ( $order, $replace, $div->plaintext );
		//$str = explode ( "/[\s]+/", $text );
		// $arr = explode(" ", $str[0]);
		// print_r($str);
		
		$parsed = preg_split ( '/ +/', $text ); // one or more spaces
		$days = array ();
		foreach ( $parsed as $temp ) {
			// echo $temp;
			if (! empty ( $temp ) && strlen ( trim ( $temp ) ) > 0) {
				// echo $temp.'='.strlen(trim($temp));
				$days [] = trim ( $temp );
			}
		}
		return $days;
	}
}

?>